﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//
using PharmacyBussinesEntities;
using PharmacyService;
using System.Web.ModelBinding;
using Microsoft.Practices.Unity;

namespace PharmacyWeb.Ventas
{
    public partial class FrmActualizarCliente : System.Web.UI.Page
    {
        private Int32 idRespaldo = 100;
        [Dependency]
        public IClienteService ClienteService { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            idRespaldo++;
            var accion = Request.QueryString["accion"];
            var idCliente = Request.QueryString["id"];
            if (accion != null && accion=="nuevo")
            {
                fvproveedor.DefaultMode = FormViewMode.Insert;
            }

        }
        public Cliente GetCliente([QueryString("id")]Int32? Id)
        {
            
            Cliente cliente = null;
            if (Id.HasValue)
            {
                cliente = ClienteService.GetClienteById(Id.Value);

            }
            return cliente;
        }

        public void ActualisarCliente(Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                ClienteService.UpdateCliente(cliente);
                Response.Redirect("FrmBuscarCliente.aspx");
            }
        }

        public void InsertCliente(Cliente cliente)
        {
            cliente.Id = idRespaldo;
            if (ModelState.IsValid)
            {
                ClienteService.AddCliente(cliente);
                Response.Redirect("FrmBuscarCliente.aspx");
            }
        }

    }
}